package com.mty.mydemo.View;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.litesuits.sdk.views.DefaultTipsView;
import com.qunduikj.sjb.R;

/**
 * @author June @http://litesuits.com
 * @date 2015-08-25
 */
public class CustomTipsView extends DefaultTipsView {

    //    private View noDateView;
    private TextView mTvTips;
    private Button mBtTips;
    private TextView mTvNodataTips;
    private ImageView animationIV;

    public CustomTipsView(Context context) {
        super(context);
        init();
    }

    public CustomTipsView(Context context, View realView) {
        super(context, realView);
        init();
    }

    private void init() {
        setLoadingView(R.layout.view_load_animate);
        setNoNetworkView(R.layout.view_no_network);
        setNoDataView(R.layout.views_no_data);

        mTvTips = (TextView) findViewById(R.id.mTvTips);
        mTvNodataTips = (TextView) findViewById(R.id.mTvNodataTips);
        mBtTips = (Button) findViewById(R.id.mBtTips);

        animationIV = (ImageView) loadingView.findViewById(com.litesuits.sdk.R.id.iv_animation);
        AnimationDrawable animationDrawable = (AnimationDrawable) animationIV.getBackground();
        animationDrawable.start();
    }

//    @Override
//    public void showLoading() {
//        super.showLoading();
//        if (animationIV != null) {
//            AnimationDrawable animationDrawable = (AnimationDrawable) animationIV.getBackground();
//            animationDrawable.start();
//        }
//    }

    public void showNoNetwork(int tipsId, int buttonTxtId, OnClickListener onClickListener) {
        showNoNetwork(getString(tipsId), getString(buttonTxtId), onClickListener);
    }

    public void showNoNetwork(CharSequence tips, CharSequence buttonTxt, OnClickListener onClickListener) {
        showNoNetwork();
        setNoNetworkDetail(tips, buttonTxt, onClickListener);
    }

    public void setNoNetworkDetail(int tipsId, int buttonTxtId, OnClickListener onClickListener) {
        setNoNetworkDetail(getString(tipsId), getString(buttonTxtId), onClickListener);
    }

    public void setNoNetworkDetail(CharSequence tips, CharSequence buttonTxt, OnClickListener onClickListener) {
        if (tips != null) {
            mTvTips.setText(tips);
        }
        if (buttonTxt != null) {
            mBtTips.setText(buttonTxt);
        }
        if (onClickListener != null) {
            mBtTips.setOnClickListener(onClickListener);
        }
    }

    public void showNoData(int resId) {
        showNoData(getString(resId));
    }

    public void showNoData(CharSequence tips) {
        showNoData();
        setNoDataDetail(tips);
    }

    public void setNoDataDetail(int resId) {
        setNoDataDetail(getString(resId));
    }

    public void setNoDataDetail(CharSequence tips) {
        if (tips != null) {
            mTvNodataTips.setVisibility(VISIBLE);
            mTvNodataTips.setText(tips);
        } else {
            mTvNodataTips.setVisibility(GONE);
        }
    }

    private String getString(int resId) {
        return resId > 0 ? getResources().getString(resId) : null;
    }

}

